<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>商品添加</title>
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->

    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!--    引入首页样式-->
    <link href="favicon.ico" rel="shortcut icon" />
    <link href="../../indexCss.css" rel="stylesheet" type="text/css">
    <style>
        body {
            padding: 0;
            margin: 0;
            position: relative;
            color: rgba(0, 0, 0, 0.68)
        }

        a {
            color: rgba(0, 0, 0, 0.68);
            cursor: pointer; /*加手图标*/
            text-decoration: none;
        }

        a:hover {
            color: #24407EAD;
        }



        section>div{
            margin: 0;
            padding: 0;
            /*background-color: rgba(119, 113, 113, 0.32);*/
        }
    </style>
</head>
<body>
<myheader></myheader>
<section>
    <div class="container" >
    <div class="row col-md-12"  style=" position:relative;top:60px;padding: 20px;">
        <div class="col-md-3 ">
            <mydiv v-bind:cls="cls" v-bind:com="com" v-bind:rcls="rcls" v-bind:rep="rep"></mydiv>
        </div>
                 <div class="col-md-2"></div><!--为了中间间隔点-->
                <div class="col-md-7" >
                        <form enctype="multipart/form-data" id="Aform3" role="form" style="padding: 50px 20px;background-color: rgb(255,255,255);">
                            <div class="form-group">
                                <label>文章标题</label><br>
                                <textarea cols="70" name="title" rows="3"></textarea>
                                <!--                            <input type="text" name="title" class="form-control">-->
                            </div>

                            <div class="form-group">
                                <label>文章正文</label><br>
                                <textarea cols="70" name="content" rows="9"></textarea>
                                <!--                            <input type="text" name="content" class="form-control">-->
                            </div>
                            <div class="form-group">
                                <input id="exampleInputFile" name="picFile" type="file"/>
                                <p class="help-block">
                                    请选择您所要上架的商品图片
                                </p>
                            </div>
                            <div class="item item-input item-select">
                                <label>请选择所属产品类</label>
                                <select  name="clsId">
                                    <option value=0>请选择</option>
                                    <option :value="c.id" v-for="c in rcls">{{c.name}}</option>
                                </select>
                                <div style="float: right">
                                    <button @click="send()" class="btn btn-success"  type="button">确认添加</button>
                                </div>
                            </div>
                        </form>
                </div>

    </div>
    </div>
</section>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<!--导入弹窗组件-->
<script src=" https://unpkg.com/sweetalert/dist/sweetalert.min.js "></script>
<!--引入vue和axios-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el:"section",
        data:{
            cls: {}, //类集合
            com: {}, //商品集合
            id:"",
            rcls: [], //资讯类集合
            rep: [], //资讯集合
        },
        created:function(){
            axios.post("/admin/selectToCommodity").then(function (response){
                v.com = response.data
            }),
            axios.post("/admin/selectToClass").then(function (response){
                v.cls = response.data
            })
            axios.post("/admin/selectToReportCls").then(function (response) {
                v.rcls = response.data;
            }),
                axios.post("/admin/selectToReport").then(function (response) {
                    v.rep = response.data;
                })
        },
        methods:{
            upda:function (id){
                location.href="/admin/admin/updateCommodity.html?id="+id;
            },
            send:function (){

                swal("", "您确认添加嘛", "warning", {
                    button: "就是它了",
                }).then((value) => {
                    if (value==true){
                        let data = new FormData(document.getElementById("Aform3"))
                        if (data.get("clsId") == 0) {
                            swal("", "请选择分类!!!", "warning")
                            return;
                        }
                        if (data.get("picFile").name == "" ) {
                            swal("", "请上传文件!!!", "warning")
                            return;
                        }
                        axios.post("/admin/reportInsert", data).then(function () {
                            swal("", "添加成功", "success").then((value) => {
                                location.reload();
                            })
                        })
                    }
                });
            }
        }
    })

</script>
<!--引入footer-->
<!--<script src="adminjs/footer.js"></script>-->
<!--引入左侧边栏组件-->
<script src="../adminjs/mydiv.js"></script>
<!--引入header-->
<script src="../adminjs/header.js"></script>
<!--背景线条-->
<script src="../adminjs/bg.js"></script>　
<!--右键出字体-->
<script src="../adminjs/bgfont.js"></script>　
</body>
</html>